//
//  HNSH_GoodsLevelTopView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/6/15.
//

#import "HNSH_GoodsLevelTopView.h"
#import "HNSH_MyTeamProgress.h"

@interface HNSH_GoodsLevelTopView ()

/* topBgImgV */
@property (nonatomic, strong) UIImageView *topBgImgV;
/* topVipImgV */
@property (nonatomic, strong) UIImageView *topVipImgV;

/* titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;

/* hydLabel */
@property (nonatomic, strong) UILabel *hydLabel;
/* ztLabel */
@property (nonatomic, strong) UILabel *ztLabel;

/* bottomView */
@property (nonatomic, strong) UIView *bottomView;

@end

@implementation HNSH_GoodsLevelTopView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appBGColor];
        [self configUI];
    }
    return self;
}

- (void)setCountString:(NSString *)countString {
    _countString = countString;
    self.titleLabel.text = [NSString stringWithFormat:@"我的好友（%@人）",countString];
    
    [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(40);
        make.bottom.mas_equalTo(0);
    }];
}

- (void)setModel:(HNSH_MyTeamModel *)model {
    _model = model;
        
    [self configTeamProgressView];
    
    [self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(40);
        make.bottom.mas_equalTo(0);
    }];
}
//530
- (void)configUI {
    UIImageView *topBgImgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 152+kNavBarAndStatusBarHeight)];
    topBgImgV.image = [UIImage imageNamed:@"mine_goods_level_top_bg"];
    [self addSubview:topBgImgV];
    self.topBgImgV = topBgImgV;
    
    
    [self configBottomTitle];
}

//配置Progress
- (void)configTeamProgressView {
    UIView *progressBgView = [[UIView alloc]initWithFrame:CGRectMake(12, kNavBarAndStatusBarHeight+12, kScreenWidth-24, 148+self.model.level_info.requirements.count*58+33)];
    progressBgView.backgroundColor = [UIColor appWhiteLabelColor];
    [self addSubview:progressBgView];
    progressBgView.layer.cornerRadius = 8.0f;
    progressBgView.layer.masksToBounds = YES;
    
    //等级
    UIImageView *levelIcon = [[UIImageView alloc]initWithFrame:CGRectMake(44, 20, 80, 80)];
    [levelIcon sd_setImageWithURL:[NSURL URLWithString:self.model.info.level_icon]];
    [progressBgView addSubview:levelIcon];
    UILabel *levelLabel = [[UILabel alloc]initWithFrame:CGRectMake(44, 104, 80, 20)];
    levelLabel.text = self.model.info.level_name;
    levelLabel.textColor = [UIColor appBlackLabelColor];
    levelLabel.font = [UIFont boldSystemFontOfSize:14];
    levelLabel.textAlignment = NSTextAlignmentCenter;
    [progressBgView addSubview:levelLabel];
    
    //我的直推：
    UILabel *hydLabel = [[UILabel alloc]initWithFrame:CGRectMake(166, 28, 150, 22)];
    hydLabel.textColor = [UIColor appBlackLabelColor];
    hydLabel.font = [UIFont boldSystemFontOfSize:16];
    self.hydLabel = hydLabel;
    [progressBgView addSubview:hydLabel];
    self.hydLabel.text = [NSString stringWithFormat:@"我的直推：%@",self.model.info.directly_count];
    self.hydLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.hydLabel.text SelectContent:@"我的直推：" CommonFont:self.hydLabel.font SpeFont:[UIFont systemFontOfSize:12] Color:[UIColor appGray666LabelColor]];
    
    //团队消费：
    UILabel *ztLabel = [[UILabel alloc]initWithFrame:CGRectMake(166, 54, 150, 22)];
    ztLabel.textColor = [UIColor appBlackLabelColor];
    ztLabel.font = [UIFont boldSystemFontOfSize:16];
    self.ztLabel = ztLabel;
    [progressBgView addSubview:ztLabel];
    self.ztLabel.text = [NSString stringWithFormat:@"团队消费：%@",self.model.info.team_consume_total];
    self.ztLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.ztLabel.text SelectContent:@"团队消费：" CommonFont:self.ztLabel.font SpeFont:[UIFont systemFontOfSize:12] Color:[UIColor appGray666LabelColor]];
    
    for (int i = 0; i < self.model.level_info.requirements.count; i ++) {
        HNSH_RequirementsModel *item = self.model.level_info.requirements[i];
        HNSH_MyTeamProgress *view1 = [[HNSH_MyTeamProgress alloc]initWithFrame:CGRectMake(0, 148+58*i, progressBgView.width, 38)];
        view1.titleLabel.text = [NSString stringWithFormat:@"%@",item.title];
        view1.desLabel.text = item.desc;
        view1.progress = item.percentage;
        view1.topColor = [UIColor appGreenColor];
        if (i == 1) {
            view1.topColor = [UIColor colorWithHexString:@"#027AFF"];
        }
        [progressBgView addSubview:view1];
    }
    
    UILabel *desLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, progressBgView.height-20-17, progressBgView.width-32, 17)];
    desLabel.text = self.model.level_info.requirement_tip;
    desLabel.textColor = [UIColor appGrayLabelColor];
    desLabel.font = [UIFont systemFontOfSize:12];
    desLabel.textAlignment = NSTextAlignmentCenter;
    [progressBgView addSubview:desLabel];
}

- (void)configBottomTitle {
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor appWhiteLabelColor];
    [self addSubview:bgView];
    self.bottomView = bgView;
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(40);
        make.bottom.mas_equalTo(0);
    }];
//    [self clipCornerWithView:bgView cornerWidth:8 cornerType:UIRectCornerTopLeft|UIRectCornerTopRight];
    
    UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"team_xiaji_icon"]];
    icon.frame = CGRectMake(16, 13, 21, 21);
    [bgView addSubview:icon];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(45, 12, 200, 22)];
    titleLabel.text = @"我的好友（0人）";
    titleLabel.textColor = [UIColor appBlackLabelColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:16];
    self.titleLabel = titleLabel;
    [bgView addSubview:titleLabel];
}

@end
